<template>
  <div class="slide">
    <div class="list" v-for="(item, i) in arr" :key="item.title">
      <div class="title" @click="titleClick(i)">
        <span>{{ item.title }}</span>
        <i class="iconfont icon-xialajiantou"></i>
      </div>
      <ul v-show="item.show">
        <li
          @click="itemClick(item.children,i2)"
          :class="{active:item2.active}"
          v-for="(item2, i2) in item.children"
          :key="item2.title"
        >
          <i class="iconfont icon-shuangjiantouyou"></i>
          <span>{{ item2.title }}</span>
        </li>
      </ul>
    </div>
  </div>
</template>
<style lang = "scss" scoped>
.slide {
  width: 200px;
  padding: 30px 20px;
  .list {
    background: #fff;
    .title {
      height: 50px;
      line-height: 50px;
      font-weight: bold;
      font-size: 20px;
      i {
        margin-left: 5px;
      }
    }
    ul {
      li {
        padding: 5px 0 10px 15px;
        i {
          margin-right: 10px;
        }
      }
      li.active{
        color: orange;
      }
    }
  }
}
</style>
<script>
export default {
  data() {
    return {
      arr: [
        {
          title: "输送泵",
          show: true,
          children: [
            { title: "齿轮输送泵KF", active: true,id:0 },
            { title: "BT泵", active: false,id:1 },
            { title: "DuroTec泵", active: false,id:2 },
            { title: "限压阀", active: false,id:3 },
          ],
        },
        {
          show: true,
          title: "流量测量",
          children: [{ title: "流量计vc", active: false,id:4 }],
        },
      ],
    };
  },
  methods: {
    titleClick(i) {
      this.arr[i].show = !this.arr[i].show;
    },
    itemClick(data,index){
      this.arr.map(item=>{
        item.children.map(item=>item.active=false)
      })
      data.forEach((item,i)=>{
        if(i==index){
          item.active=true
          console.log(item.id)
          this.$emit('change',item)
        }else{
          item.active=false
        }
      })

    }
  },
};
</script>
 
